<?php

namespace App\Admin\Controllers;

use App\Models\AdminRegion;
use Dcat\Admin\Http\Controllers\AdminController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class RegionController extends AdminController
{

    public function cities(Request $request)
    {
        $provinceId = $request->get('q');

        return AdminRegion::where('parent_id', $provinceId)->get(['id', DB::raw('name as text')]);
    }

    public function districts(Request $request)
    {
        $cityId = $request->get('q');

        return AdminRegion::where('parent_id', $cityId)->get(['id', DB::raw('name as text')]);

    }
}

